"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _jsxRuntime = require("react/jsx-runtime");

var _icons = require("@ant-design/icons");

var _antdV = require("antd-v4");

var _classnames = _interopRequireDefault(require("classnames"));

var _react = _interopRequireWildcard(require("react"));

require("./index.less");

/**
 * 在 form 的 label 后面增加一个 tips 来展示一些说明文案
 *
 * @param props
 */
var LabelIconTip = function LabelIconTip(props) {
  var label = props.label,
      tooltip = props.tooltip,
      ellipsis = props.ellipsis,
      subTitle = props.subTitle;

  var _useContext = (0, _react.useContext)(_antdV.ConfigProvider.ConfigContext),
      getPrefixCls = _useContext.getPrefixCls;

  if (!tooltip && !subTitle) {
    return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
      children: label
    });
  }

  var className = getPrefixCls('pro-core-label-tip');
  var tooltipProps = typeof tooltip === 'string' || /*#__PURE__*/_react.default.isValidElement(tooltip) ? {
    title: tooltip
  } : tooltip;
  var icon = (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.icon) || (0, _jsxRuntime.jsx)(_icons.InfoCircleOutlined, {});
  return (0, _jsxRuntime.jsxs)("div", {
    className: className,
    onMouseDown: function onMouseDown(e) {
      return e.stopPropagation();
    },
    onMouseLeave: function onMouseLeave(e) {
      return e.stopPropagation();
    },
    onMouseMove: function onMouseMove(e) {
      return e.stopPropagation();
    },
    children: [(0, _jsxRuntime.jsx)("div", {
      className: (0, _classnames.default)("".concat(className, "-title"), (0, _defineProperty2.default)({}, "".concat(className, "-title-ellipsis"), ellipsis)),
      children: label
    }), subTitle && (0, _jsxRuntime.jsx)("div", {
      className: "".concat(className, "-subtitle"),
      children: subTitle
    }), tooltip && (0, _jsxRuntime.jsx)(_antdV.Tooltip, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, tooltipProps), {}, {
      children: (0, _jsxRuntime.jsx)("span", {
        className: "".concat(className, "-icon"),
        children: icon
      })
    }))]
  });
};

var _default = /*#__PURE__*/_react.default.memo(LabelIconTip);

exports.default = _default;